Skip to content

Conversation

Dhruvgoel3829
Copy link

@Dhruvgoel3829 Dhruvgoel3829 commented Oct 2, 2024

Describe your change:

Added Three algorithms under python/maths/gametheory/

Algorithms added:

  1. MiniMax
  2. AlphaBetaPruning
  3. MCTS
  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass labels Oct 2, 2024
@algorithms-keeper algorithms-keeper bot added require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 2, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

board = [[0, 0, 0], [0, 0, 0], [0, 0, 0]]


def Gameboard(board):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/AlphaBetaPruning/alphabetapruning.py, please provide doctest for the function Gameboard

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Gameboard

Please provide return type hint for the function: Gameboard. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: board

print("===============")


def Clearboard(board):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/AlphaBetaPruning/alphabetapruning.py, please provide doctest for the function Clearboard

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: Clearboard

Please provide return type hint for the function: Clearboard. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: board

board[x][y] = 0


def winningPlayer(board, player):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/AlphaBetaPruning/alphabetapruning.py, please provide doctest for the function winningPlayer

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: winningPlayer

Please provide return type hint for the function: winningPlayer. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: board

Please provide type hint for the parameter: player

return False


def gameWon(board):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/AlphaBetaPruning/alphabetapruning.py, please provide doctest for the function gameWon

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: gameWon

Please provide return type hint for the function: gameWon. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: board

return winningPlayer(board, 1) or winningPlayer(board, -1)


def printResult(board):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/AlphaBetaPruning/alphabetapruning.py, please provide doctest for the function printResult

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: printResult

Please provide return type hint for the function: printResult. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: board


# Game play input validation
# Input is considered valid only if its one of the 3 availiable options and does not cause a negative amount of cubes on the table.
def validateInput(message):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function validateInput

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: validateInput

Please provide return type hint for the function: validateInput. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: message

print(f"Wrong choice, try again. Availiable options are: 1 or 2 or {K}: ")


def plural(choice):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function plural

Please provide return type hint for the function: plural. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: choice

# ==================== 1. MiniMax for the optimal choice from MAX ==================
# It recursively expands the whole tree and returns the list [score, move],
# meaning the pair of best score tighten to the actual move that caused it.
def MiniMax(state, player):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function MiniMax

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: MiniMax

Please provide return type hint for the function: MiniMax. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: state

Please provide type hint for the parameter: player

0,
] # We really do not care on the move at this point

availiableChoices = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: availiableChoices


# ===== Παίζει ο χρήστης =====
else:
userChoice = validateInput(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: userChoice

@algorithms-keeper algorithms-keeper bot removed the require descriptive names This PR needs descriptive function and/or variable names label Oct 2, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

# If the current state is not final, we don't care on the current evaluation so we simply initialise it to 0.


def evaluate(state, player):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function evaluate

Please provide return type hint for the function: evaluate. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: state

Please provide type hint for the parameter: player

return 0


def gameOver(remainingCubes, player):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function gameOver

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: gameOver

Please provide return type hint for the function: gameOver. If the function does not return a value, please provide the type hint as: def function() -> None:

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: remainingCubes

Please provide type hint for the parameter: remainingCubes

Please provide type hint for the parameter: player



# M input validation
def validateM(message):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function validateM

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: validateM

Please provide return type hint for the function: validateM. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: message



# K input validation
def validateK(message):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function validateK

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: validateK

Please provide return type hint for the function: validateK. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: message


# Game play input validation
# Input is considered valid only if its one of the 3 availiable options and does not cause a negative amount of cubes on the table.
def validateInput(message):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function validateInput

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: validateInput

Please provide return type hint for the function: validateInput. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: message

print(f"Wrong choice, try again. Availiable options are: 1 or 2 or {K}: ")


def plural(choice):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function plural

Please provide return type hint for the function: plural. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: choice

# ==================== 1. MiniMax for the optimal choice from MAX ==================
# It recursively expands the whole tree and returns the list [score, move],
# meaning the pair of best score tighten to the actual move that caused it.
def MiniMax(state, player):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file maths/Game Theory/minimax/minimax.py, please provide doctest for the function MiniMax

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: MiniMax

Please provide return type hint for the function: MiniMax. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: state

Please provide type hint for the parameter: player

0,
] # We really do not care on the move at this point

availiableChoices = []

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: availiableChoices


# ===== Παίζει ο χρήστης =====
else:
userChoice = validateInput(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable and function names should follow the snake_case naming convention. Please update the following name accordingly: userChoice

@Dhruvgoel3829 Dhruvgoel3829 changed the title GameTheory added minimax algorithm added Oct 2, 2024
@cclauss
Copy link
Member

cclauss commented Oct 22, 2024

Closing require_type_hints PRs to prepare for Hacktoberfest

@cclauss cclauss closed this Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html tests are failing Do not merge until tests pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants